Skip to content

PDO: Migrate maxlen of pdo_column_data from size_t to zend_long #19144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

marc-mabe
Copy link
Contributor

@marc-mabe marc-mabe commented Jul 16, 2025

This is returned in PDOStatement::getColumnMeta as len documented as "The length of this column. Normally -1 for types other than floating point decimals."

Also, It was as FIXME already.

  • pgsql: PQfsize: returns the space allocated for this column in a database row, in other words the size of the server's internal representation of the data type. (Accordingly, it is not really very useful to clients.) A negative value indicates the data type is variable-length.
  • dblib: dbcollen: The maximum length, in bytes, of the data for the particular column. If the column number is not in range, dbcollen returns -1.
  • firebird: XSQLVAR.sqllen -> ISC_SHORT -> signed short: length of data area
  • mysql: MYSQL_FIELD.length
    • MYSQLND_FIELD.length -> zend_ulong: Width of column (create length)
    • libmysql: unsigned long length : Width of column (create length)

I noticed this during my work of 64bit integers on 32bit arch where it would was failing: https://github.com/php/php-src/actions/runs/16311803646/job/46068812948#step:9:2782

@@ -533,7 +533,7 @@ static inline pdo_dbh_object_t *php_pdo_dbh_fetch_object(zend_object *obj) {
/* describes a column */
struct pdo_column_data {
zend_string *name;
size_t maxlen;
zend_long maxlen;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't this be more accurate?

Suggested change
zend_long maxlen;
ssize_t maxlen;

@SakiTakamachi
Copy link
Member

Hmm... It seems that in pdo_odbc, a ulong value is passed here (according to the ODBC specification, an unsigned 64-bit integer might be passed).

col->maxlen = S->cols[colno].datalen = colsize;

I suppose such columns are quite rare in practice, but this does introduce a slight possibility of a BC break.

One alternative might be to add a flag instead of changing the type to signed.

What do you think? @NattyNarwhal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants